class Solution {
public:
    int removeElement(vector<int>& num, int val) {
        int n = num.size();
        int j = 0;
        for (int i = 0; i < n; i++) {
            if (num[i] != val) {
                num[j++] = num[i];
            }
        }
        return j;
    }
};